package districting;

import java.util.Comparator;
import java.util.List;

import com.vividsolutions.jts.geom.Point;

public class PollingBoothDistanceComparatorB implements
      Comparator<PollingBooth> {

   Point point;
   List<Point> points;

   public PollingBoothDistanceComparatorB(List<Point> points, Point point) {
      this.points = points;
      this.point = point;
   }

   @Override
   public int compare(PollingBooth pb0, PollingBooth pb1) {
      double dist0 = 0;
      double dist1 = 0;
      for (Point point : points) {
         dist0 += pb0.getPoint().distance(point);
         dist1 += pb1.getPoint().distance(point);
      }
      dist0 /= pb0.getPoint().distance(point);
      dist1 /= pb1.getPoint().distance(point);
      if (dist0 > dist1) {
         return -1;
      } else if (dist0 < dist1) {
         return 1;
      } else {
         return 0;
      }
   }

}
